#!/bin/bash
#chkconfig:2345 30 80
#description:elasticsearch
#processname:elasticsearch

export JAVA_HOME=/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.232.b09-0.el7_7.x86_64
export PATH=$JAVA_HOME/bin:$PATH



case $1 in
            start)
                su elastic -c "/home/root/app/elasticsearch-7.4.0/bin/elasticsearch -d"
                ;;
            stop)
                es_pid=`ps aux|grep elasticsearch | grep -v 'grep elasticsearch' | awk '{print $2}'
                kill -9 $es_pid
                ;;
            status)
                jps
                ;;
            restart)
                es_pid=`ps aux|grep elasticsearch | grep -v 'grep elasticsearch' | awk '{print $2}'
                kill -9 $es_pid
                su elastic -c "/home/root/app/elasticsearch-7.4.0/bin/elasticsearch -d"
                ;;
            *)
                echo "require start|stop|status|restart"
                ;;
esac